<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>screenCaptureTest</title>
    <style>
        body{
                background-color:gray;
            }
        .box {
            width: 200px;
            height: 150px;
            line-height: 150px;
            text-align: center;
            background-color: orange;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -100px;
            margin-top: -75px;
         }
         a{
            font-size:3em;
         }
    </style>
</head>
<body>
<div id="error"></div>
<video id="video" width="500px" height="500px" autoplay="autoplay"></video>
<canvas id="canvas" width="500px" height="500px"></canvas>
<div class="box">
    <input type="button" title="申请共享屏幕" value="申请共享屏幕" onclick="getScreenStream()"/>
</div>
</body>
<script>
    function getScreenStream() {
        navigator.mediaDevices.getDisplayMedia({ video: true })
          .then((stream) => {
            document.getElementById("error").innerHTML = "grant"
          })
          .catch((error) => {
            document.getElementById("error").innerHTML = "deny"
          });
    }

    function getResult(){
        return document.getElementById("error").innerHTML
    }
</script>
</html>